<?php

//

enum  Httpcode:int  //这里的类型是修饰case的
{
    case OK = 200;
    case NOT_FOUND = 404;
    case SERVER_ERROR = 500;

    //实例方法：获取单个消息
    public function message():string
    {
        return match($this){      //因为case条目是单例对象，这里必须是实例化对象$this;
            self::OK=>'success',
            self::NOT_FOUND=>'not found',
            self::SERVER_ERROR=>'error'
        };
    }
}

class Json
{
    static public function resp(HttpCode $code): string
    {
        return match($code) {
            HttpCode::OK => "成功: {$code->message()}",
            HttpCode::NOT_FOUND => "警告: {$code->message()}",
            default => "错误: {$code->value}"
        };
    }
}

var_dump(Json::resp(Httpcode::OK));